﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSetPaperList : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected CheckBoxList CBLPaperID;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labUserInfo;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "";

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string str = ",";
            for (int i = 0; i < this.CBLPaperID.Items.Count; i++)
            {
                if (this.CBLPaperID.Items[i].Selected)
                {
                    str = str + this.CBLPaperID.Items[i].Value + ",";
                }
            }
            if (str.Trim() == ",")
            {
                str = "";
            }
            string str2 = "";
            if (this.string_0.Trim() == "L")
            {
                str2 = "LookPaperID";
            }
            if (this.string_0.Trim() == "C")
            {
                str2 = "CheckPaperID";
            }
            this.publicFun_0.ExecuteSql("update UserPower set " + str2 + "='" + str + "' where UserCode='" + this.ViewState["UserCode"].ToString().Trim() + "'");
            base.Response.Write("<script>alert('设置试卷范围操作成功！')</script>");
        }

        private void method_0()
        {
            string str = "";
            string str2 = "";
            if (this.string_0.Trim() == "L")
            {
                str2 = "b.LookPaperID";
            }
            if (this.string_0.Trim() == "C")
            {
                str2 = "b.CheckPaperID";
            }
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand(string.Concat(new object[] { "select a.UserCode,a.UserName,", str2, " from UserInfo a,UserPower b where a.UserCode=b.UserCode and a.ID=", this.int_0 }), connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    this.ViewState["UserCode"] = reader["UserCode"].ToString();
                    if (this.string_0.Trim() == "L")
                    {
                        str = reader["LookPaperID"].ToString();
                        this.labUserInfo.Text = "设置用户〖" + reader["UserName"].ToString() + "(" + reader["UserCode"].ToString() + ")〗查看考卷明细权限信息";
                    }
                    if (this.string_0.Trim() == "C")
                    {
                        this.labUserInfo.Text = "设置用户〖" + reader["UserName"].ToString() + "(" + reader["UserCode"].ToString() + ")〗查看批改试卷权限信息";
                        str = reader["CheckPaperID"].ToString();
                    }
                    try
                    {
                        if (str.Trim() != "")
                        {
                            string[] strArray = str.Split(new char[] { ',' });
                            for (int i = 0; i < strArray.Length; i++)
                            {
                                if (strArray[i].Trim() != "")
                                {
                                    this.CBLPaperID.Items.FindByValue(strArray[i].Trim()).Selected = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        base.Response.Write(@"<script>alert('由于部分试卷已删除，所以查看试卷范围未读齐全！\n\n请重新设置试卷范围！')</script>");
                        return;
                    }
                }
                reader.Close();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
                base.Response.Write("<script>alert('由于部分试卷已删除，所以读取试卷范围未读齐全！')</script>");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"]);
                this.string_0 = Convert.ToString(base.Request["Flag"]);
                if (!base.IsPostBack)
                {
                    base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    base.Response.Cache.SetNoStore();
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.int_0 != 0)
                        {
                            string strSql = "";
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand("select ManagPower,AddPaper,ManagPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                if (reader["ManagPower"].ToString() != "Y")
                                {
                                    this.butDefault.Visible = false;
                                }
                                strSql = "select ID,ExamName from PaperInfo  order by ID desc";
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                            this.CBLPaperID.DataTextField = "ExamName";
                            this.CBLPaperID.DataValueField = "ID";
                            this.CBLPaperID.DataSource = this.publicFun_0.RetrunDataView(strSql);
                            this.CBLPaperID.DataBind();
                            this.method_0();
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
        }
    }
}

